from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-04 14:02:11.486732
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 04, Jul, 2022
Time: 14:02:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.6923
Nobs: 707.000 HQIC: -50.0486
Log likelihood: 8832.77 FPE: 1.46810e-22
AIC: -50.2729 Det(Omega_mle): 1.29377e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298594 0.057506 5.192 0.000
L1.Burgenland 0.106324 0.037783 2.814 0.005
L1.Kärnten -0.109413 0.020013 -5.467 0.000
L1.Niederösterreich 0.211061 0.078932 2.674 0.007
L1.Oberösterreich 0.105211 0.077292 1.361 0.173
L1.Salzburg 0.256860 0.040407 6.357 0.000
L1.Steiermark 0.045513 0.052645 0.865 0.387
L1.Tirol 0.109064 0.042738 2.552 0.011
L1.Vorarlberg -0.058674 0.037057 -1.583 0.113
L1.Wien 0.040863 0.068370 0.598 0.550
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048486 0.120509 0.402 0.687
L1.Burgenland -0.034257 0.079179 -0.433 0.665
L1.Kärnten 0.041145 0.041939 0.981 0.327
L1.Niederösterreich -0.167354 0.165410 -1.012 0.312
L1.Oberösterreich 0.423933 0.161973 2.617 0.009
L1.Salzburg 0.288393 0.084676 3.406 0.001
L1.Steiermark 0.100722 0.110323 0.913 0.361
L1.Tirol 0.319065 0.089561 3.563 0.000
L1.Vorarlberg 0.027956 0.077656 0.360 0.719
L1.Wien -0.040650 0.143277 -0.284 0.777
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187202 0.029438 6.359 0.000
L1.Burgenland 0.090385 0.019342 4.673 0.000
L1.Kärnten -0.008043 0.010245 -0.785 0.432
L1.Niederösterreich 0.264390 0.040407 6.543 0.000
L1.Oberösterreich 0.138635 0.039567 3.504 0.000
L1.Salzburg 0.045835 0.020685 2.216 0.027
L1.Steiermark 0.019752 0.026950 0.733 0.464
L1.Tirol 0.091612 0.021878 4.187 0.000
L1.Vorarlberg 0.056809 0.018970 2.995 0.003
L1.Wien 0.114712 0.035000 3.277 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111646 0.029940 3.729 0.000
L1.Burgenland 0.045348 0.019672 2.305 0.021
L1.Kärnten -0.013690 0.010420 -1.314 0.189
L1.Niederösterreich 0.192611 0.041095 4.687 0.000
L1.Oberösterreich 0.302223 0.040241 7.510 0.000
L1.Salzburg 0.108183 0.021037 5.142 0.000
L1.Steiermark 0.104810 0.027409 3.824 0.000
L1.Tirol 0.103691 0.022251 4.660 0.000
L1.Vorarlberg 0.067451 0.019293 3.496 0.000
L1.Wien -0.022963 0.035596 -0.645 0.519
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134678 0.054624 2.466 0.014
L1.Burgenland -0.051576 0.035890 -1.437 0.151
L1.Kärnten -0.044339 0.019010 -2.332 0.020
L1.Niederösterreich 0.156596 0.074976 2.089 0.037
L1.Oberösterreich 0.139353 0.073418 1.898 0.058
L1.Salzburg 0.286745 0.038382 7.471 0.000
L1.Steiermark 0.047842 0.050007 0.957 0.339
L1.Tirol 0.166909 0.040596 4.111 0.000
L1.Vorarlberg 0.092844 0.035200 2.638 0.008
L1.Wien 0.073242 0.064944 1.128 0.259
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055262 0.043431 1.272 0.203
L1.Burgenland 0.037567 0.028536 1.316 0.188
L1.Kärnten 0.051101 0.015115 3.381 0.001
L1.Niederösterreich 0.217158 0.059613 3.643 0.000
L1.Oberösterreich 0.294830 0.058374 5.051 0.000
L1.Salzburg 0.047900 0.030517 1.570 0.117
L1.Steiermark 0.001876 0.039760 0.047 0.962
L1.Tirol 0.140573 0.032277 4.355 0.000
L1.Vorarlberg 0.073959 0.027987 2.643 0.008
L1.Wien 0.080652 0.051636 1.562 0.118
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175367 0.051954 3.375 0.001
L1.Burgenland -0.002534 0.034136 -0.074 0.941
L1.Kärnten -0.062990 0.018081 -3.484 0.000
L1.Niederösterreich -0.080961 0.071312 -1.135 0.256
L1.Oberösterreich 0.194299 0.069830 2.782 0.005
L1.Salzburg 0.056492 0.036506 1.547 0.122
L1.Steiermark 0.236265 0.047562 4.967 0.000
L1.Tirol 0.497550 0.038612 12.886 0.000
L1.Vorarlberg 0.044707 0.033479 1.335 0.182
L1.Wien -0.055670 0.061770 -0.901 0.367
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169830 0.059094 2.874 0.004
L1.Burgenland -0.012234 0.038827 -0.315 0.753
L1.Kärnten 0.063938 0.020566 3.109 0.002
L1.Niederösterreich 0.207135 0.081112 2.554 0.011
L1.Oberösterreich -0.075360 0.079427 -0.949 0.343
L1.Salzburg 0.213105 0.041523 5.132 0.000
L1.Steiermark 0.125754 0.054099 2.325 0.020
L1.Tirol 0.067173 0.043918 1.530 0.126
L1.Vorarlberg 0.119280 0.038080 3.132 0.002
L1.Wien 0.123889 0.070259 1.763 0.078
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.363286 0.034235 10.611 0.000
L1.Burgenland 0.007454 0.022494 0.331 0.740
L1.Kärnten -0.023762 0.011914 -1.994 0.046
L1.Niederösterreich 0.215823 0.046991 4.593 0.000
L1.Oberösterreich 0.204799 0.046015 4.451 0.000
L1.Salzburg 0.043451 0.024056 1.806 0.071
L1.Steiermark -0.014840 0.031342 -0.473 0.636
L1.Tirol 0.106073 0.025443 4.169 0.000
L1.Vorarlberg 0.069417 0.022061 3.147 0.002
L1.Wien 0.030628 0.040703 0.752 0.452
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037559 0.137958 0.194098 0.155394 0.114998 0.102348 0.057359 0.217722
Kärnten 0.037559 1.000000 -0.015509 0.134328 0.055952 0.095257 0.435663 -0.053282 0.093258
Niederösterreich 0.137958 -0.015509 1.000000 0.335225 0.141097 0.294005 0.092395 0.176607 0.312798
Oberösterreich 0.194098 0.134328 0.335225 1.000000 0.226869 0.324772 0.176260 0.164439 0.263994
Salzburg 0.155394 0.055952 0.141097 0.226869 1.000000 0.137870 0.116609 0.138551 0.129970
Steiermark 0.114998 0.095257 0.294005 0.324772 0.137870 1.000000 0.145593 0.129038 0.073345
Tirol 0.102348 0.435663 0.092395 0.176260 0.116609 0.145593 1.000000 0.112493 0.141841
Vorarlberg 0.057359 -0.053282 0.176607 0.164439 0.138551 0.129038 0.112493 1.000000 0.004101
Wien 0.217722 0.093258 0.312798 0.263994 0.129970 0.073345 0.141841 0.004101 1.000000